<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
</head>
<body>
    <div id="app-29">
        <div style="width: 100%; height: 20px; background: #00BFFF;">
            <!-- <router-link to="/index">首页</router-link> -->
            <button type="button" @click="test">首页按钮</button>
            <button type="button" @click="test2">go()</button>
            <router-view></router-view>
        </div>
    </div>

    <script type="text/javascript">
        <!-- vue 的路由旨在为单页面应用开发提供便携 -->
        // 1. 定义链接跳转的模板（组件）
        const t1 = {
            template: `<div style="width: 400px; height: 200px; border: blue 1px solid" >
                    index
                    </div>`
        };


        // 2. 定义路由
        const my_router = new VueRouter({
           routes: [
               {
                   path: '/index',
                   name: "r1",
                   component: t1
               }
           ]
        });
        // 3. 引用路由
        var vm = new Vue({
           el: '#app-29',
            router: my_router,
            methods: {
               test: function () {
                   // js 代码实现路由跳转，编程式导航

                   // 1. 字符串
                   my_router.push("/index");
                   // my_router.replace("/index");

                   // 2. 对象
                   // my_router.push({path: "/index"});

                   // 3. 命名的路由 name 参数指的是定义路由时指定的名字
                   // my_router.push({name: "r1", params: {id: 101}});

                   // 4. URL 传值，相当于 /index?id=101
                   // my_router.push({path: "/index", query: {id: 101}});
               },
                test2: function () {
                    my_router.go(-1);
                }
            }
        });
    </script>

</body>
</html>